﻿// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_BOM_TECHNIC_ITEM
// * CreateDate    : 2013-11-15 23:15:00
// * Creater       : CodeSmith
// * LastChangeDate: 2013-11-15 23:15:00
// * LastChanger   : 2013-11-15 23:15:00
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Bpt
{
    /// <summary>
    /// BomTechnicItem
    /// </summary>
    public partial class BomTechnicItemBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objBomTechnicItemEntity">Entity</param>
        /// <returns>Entity</returns>
        public static BomTechnicItemEntity GetBomTechnicItem(BomTechnicItemEntity objBomTechnicItemEntity)
        {
            return DataAccess.SelectSingle<BomTechnicItemEntity>(objBomTechnicItemEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objBomTechnicItemEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertBomTechnicItem(BomTechnicItemEntity objBomTechnicItemEntity)
        {
            return DataAccess.Insert(objBomTechnicItemEntity);
        }

        public static bool InsertBomTechnicItem(List<BomTechnicItemEntity> objBomTechnicItemEntityList)
        {
            return DataAccess.Insert(objBomTechnicItemEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objBomTechnicItemEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateBomTechnicItem(BomTechnicItemEntity objBomTechnicItemEntity)
        {
            return DataAccess.Update(objBomTechnicItemEntity);
        }

        public static bool UpdateBomTechnicItem(List<BomTechnicItemEntity> objBomTechnicItemEntityList)
        {
            return DataAccess.Update<BomTechnicItemEntity>(objBomTechnicItemEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objBomTechnicItemEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteBomTechnicItem(BomTechnicItemEntity objBomTechnicItemEntity)
        {
            return DataAccess.Delete(objBomTechnicItemEntity);
        }

        public static bool DeleteBomTechnicItem(List<BomTechnicItemEntity> objBomTechnicItemEntityList)
        {
            return DataAccess.Delete<BomTechnicItemEntity>(objBomTechnicItemEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetBomTechnicItemAll()
        {
            return DataAccess.SelectAllDataSet<BomTechnicItemEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<BomTechnicItemEntity> GetBomTechnicItemAllList()
        {
            return DataAccess.SelectAll<BomTechnicItemEntity>();
        }
        #endregion

        public static DataSet GetBomTechnicItemAllDsByTechId(string techId)
        {
            if (string.IsNullOrEmpty(techId))
                return null;
            string sql = @"select bti.*,pt.TECHNIC_NAME,pt.TECHNIC_CODE 
from BOM_TECHNIC_ITEM bti
left join PROD_TECHNIC pt on bti.TECHNIC_ID=pt.TECHNIC_ID
where bti.BOM_TECHNIC_ID='{0}'";
            sql=string.Format(sql,techId);
            return DataAccess.SelectDataSet(sql);
        }

        public static List<BomTechnicItemEntity> GetListBomTechnicItemAllListByTechId(string techId)
        {
            if (string.IsNullOrEmpty(techId))
                return null;
            return DataAccess.Select<BomTechnicItemEntity>(new BomTechnicItemEntity { BomTechnicId = techId });
        }

        public static bool Save(List<BomTechnicItemEntity> news,List<BomTechnicItemEntity> updates,List<BomTechnicItemEntity> dels)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    DataAccess.Delete(dels, broker);
                    DataAccess.Update(updates, broker);
                    DataAccess.Insert(news, broker);
                    broker.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }

        }

    }


}

